package com.logic.modular.game.battle.process.skillEffectHandle.impl;

import com.logic.modular.game.battle.panel.attribute.PlayerHeroAttributeServiceImpl;
import com.logic.modular.game.battle.panel.attribute.domain.EffectStatus;
import com.logic.modular.game.battle.panel.attribute.domain.PlayerHeroAttribute;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffectServiceImpl;
import com.logic.modular.game.battle.process.skillEffectHandle.base.BaseSkillEffectStrategy;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

public class StatusStrategy {
    @Component
    public static class BaseStatusStrategy extends BaseSkillEffectStrategy {
        @Resource
        public PvpSkillEffectServiceImpl pvpSkillEffectService;

        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {

            return pvpSkillEffect;
        }

        @Override
        public PvpSkillEffect apply(PvpSkillEffect pvpSkillEffect) {
            return pvpSkillEffect;
        }
    }

    // 33	持续性恢复	休整状态，每回合恢复兵力，行动时恢复	currentForce			11
    @Component
    public static class Status33 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 35	绝粮	无法恢复兵力	currentForce	[32,33]		11
    @Component
    public static class Status35 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 36	先手	判断顺序   先手状态 > 速度				11
    @Component
    public static class Status36 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 37	连击	普通攻击之后，会再次发动一次普通攻击				11
    @Component
    public static class Status37 extends BaseStatusStrategy {
        @Resource
        private PlayerHeroAttributeServiceImpl attributeService;

        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            effectHandle2.tryTriggerJudgment(pvpSkillEffect);
            effectHandle2.logTriggerFailReasons(pvpSkillEffect);
            if (pvpSkillEffect.status.getIsTrigger() == 1) {
                apply(pvpSkillEffect);
            }
            attributeService.refreshPanel(pvpSkillEffect);
            return pvpSkillEffect;
        }

        public PvpSkillEffect apply(PvpSkillEffect pvpSkillEffect) {
            // 添加状态
            String battleUUID = pvpSkillEffect.getBattleUUID();

            Long targetPlayerHeroId = pvpSkillEffect.getTargetPlayerHeroId();
            PlayerHeroAttribute targetAttribute = attributeService.get(battleUUID, targetPlayerHeroId);

            Long sourcePlayerHeroId = pvpSkillEffect.getSourcePlayerHeroId();
            PlayerHeroAttribute sourceAttribute = attributeService.get(battleUUID, sourcePlayerHeroId);

            Map<Long, EffectStatus> status = targetAttribute.getStatus();
            EffectStatus build = EffectStatus.getEffectStatus(pvpSkillEffect, sourceAttribute);
            status.put(37L, build);
            targetAttribute.setStatus(status);
            attributeService.saveCache(targetAttribute);
            return pvpSkillEffect;
        }
    }

    // 38	洞察	免疫（混乱，缴械，技穷，暴走，挑衅）		[23,24,25,26,54]		11
    @Component
    public static class Status38 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            Set<Long> immunityList = pvpSkillEffect.getImmunityList();
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 39	规避	免疫伤害，一般以次为单位		[51,52]		11
    @Component
    public static class Status39 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            Set<Long> immunityList = pvpSkillEffect.getImmunityList();
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 41	倒戈	物理吸血(<= 最大兵力)，例如10%的倒戈，如果对对方造成200兵力的物理伤害，则会恢复20兵力				11
    @Component
    public static class Status41 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 42	攻心	策略吸血等同 42				11
    @Component
    public static class Status42 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 40	无视规避	无视规避，对方有规避状态的时候，仍然可以对对方造成伤害，对方的规避状态不会消失				11
    @Component
    public static class Status40 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 43	无视兵种相克	兵种被克的时候，不会受到减伤效果				11
    @Component
    public static class Status43 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 44	反击	受到普通攻击时，会进行反击（对攻击你的武将造成物理伤害）				11
    @Component
    public static class Status44 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }

    // 45	分兵	进入分兵之后，普通攻击时，会对目标武将旁边的武将造成伤害，如果目标是中间武将，则会对两边的两个武将都造成伤害				11
    @Slf4j
    @Component
    public static class Status45 extends BaseStatusStrategy {
        @Resource
        private BloodVolumeStrategy.BloodVolume51 physicsAttackStrategy;

        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }

        /**
         * 分兵伤害 45
         *
         * @param actHeroAttribute   攻击者属性
         * @param defWJ              防御者属性
         * @param targetPlayerHeroId 目标武将
         */
        public void apply(
                PlayerHeroAttribute actHeroAttribute,
                PlayerHeroAttribute defWJ,
                List<PlayerHeroAttribute> targetPlayerHeroId
        ) {
            EffectStatus heroStatus = actHeroAttribute.getStatus().get(45L);
            // if (heroStatus==null){
            //     return;
            // }
            // Double value = heroStatus.getMagicInfluence();
            // boolean b = attributeService.statusUseAndRefresh(actHeroAttribute, 45L);
            // if (b) {
            //     List<Object> obtainPvpRanKs = new ArrayList<>();
            //     Integer rankOrder = defWJ.getRankOrder();
            //     for (int i = -1; i < 1; i++) {
            //         if (i != 0) {
            //             int res = rankOrder + i;
            //             if (res > 1) {
            //                 obtainPvpRanKs.add(res);
            //             }
            //         }
            //     }
            //     if (!obtainPvpRanKs.isEmpty()){
            //         List<PlayerHeroAttribute> def = targetPlayerHeroId.stream()
            //                 .filter(item -> obtainPvpRanKs.contains(item.getRankOrder()))
            //                 .map(item -> attributeService.get(actHeroAttribute.getBattleId(), item.getId()))
            //                 .collect(Collectors.toList());
            //         for (PlayerHeroAttribute target : def) {
            //             PvpSkillEffect skillEffect = target.getStatus().get(45L).getSkillEffect();
            //             physicsAttackStrategy.actionApply(skillEffect);
            //         }
            //     }else {
            //         log.info("分兵失败,分兵目标数量为0");
            //     }
            // }
        }

    }

    // 46	援护	施法者承担伤害				11
    @Component
    public static class Status46 extends BaseStatusStrategy {
        @Override
        public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
            return super.applyEffect(pvpSkillEffect);
        }
    }
}
